package com.googlecode.intellimars.guitest;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.peer.PeerFactory;
import com.intellij.ui.content.Content;
import org.jetbrains.annotations.NotNull;

public class GuiSamplePlugin implements ProjectComponent {
    private static final String TOOL_WINDOW_ID = "GUI Test";
    private Project project;
    private GuiSampleWindow guiSampleWindow;

    public GuiSamplePlugin(Project _project) {
        project = _project;
    }

    public void initComponent() {
        // TODO: insert component initialization logic here
    }

    public void disposeComponent() {
        // TODO: insert component disposal logic here
    }

    @NotNull
    public String getComponentName() {
        return "GuiSamplePlugin";
    }

    public void projectOpened() {
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        ToolWindow toolWindow = toolWindowManager.registerToolWindow(TOOL_WINDOW_ID, true, ToolWindowAnchor.BOTTOM);
        PeerFactory peerFactory = PeerFactory.getInstance();
        guiSampleWindow = new GuiSampleWindow(project);
        Content content = peerFactory.getContentFactory().createContent(guiSampleWindow.getRootPanel(), "", false);
        toolWindow.getContentManager().addContent(content);
   }

    public void projectClosed() {
        ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
        toolWindowManager.unregisterToolWindow(TOOL_WINDOW_ID);
    }
}
